package 力扣日常刷题.木22一月.第07天0115;

/**
 * @author 帅小伙
 * @date 2022/1/15
 * @description
 */
public class Demo08动态规划中等粉刷房子 {

    public int minCost(int[][] costs) {
        int[][] dp = new int[costs.length+1][3];

        for (int i = 0; i < costs.length; i++) {
            // 当前屋子涂0色 == 价格 +  前一个房子 涂 1色和2色最小值
            dp[i+1][0] = costs[i][0] + Math.min(dp[i][1],dp[i][2]);
            dp[i+1][1] = costs[i][1] + Math.min(dp[i][0],dp[i][2]);
            dp[i+1][2] = costs[i][2] + Math.min(dp[i][1],dp[i][0]);
        }
        return Math.min(dp[costs.length][0],Math.min(dp[costs.length][1],dp[costs.length][2]));
    }
}
